﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CheemsControl.Converters
{
    /// <summary>
    /// 字体大小倍数转换
    /// </summary>
    public class FontSizeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double fontSize && parameter != null && double.TryParse(parameter.ToString(), out double scale))
            {
                // 使用传入的 ConverterParameter 倍数进行转换
                return fontSize * scale;
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double fontSize && parameter != null && double.TryParse(parameter.ToString(), out double scale))
            {
                // 将字体大小反向按倍数缩放回去
                return fontSize / scale;
            }
            return value;
        }
    }
}
